/* //2010-05-27 v1.0*/
;
(function($) {
	$.extend({
		fwAlert:function (id,title,model){
			var model=model==undefined?"alert-danger":model;
			model=model=='success'?"alert-success":"alert-danger";
			$(".llsalert").remove();
			var _html="<div class='llsalert login-err alert "+model+" ng-binding ng-hide' style='width:99%;margin-top:10px;margin-bottom:10px;'><button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;</button>"+title+"</div>";
			$("#"+id).append(_html);
		}
	});	
	 
	$.fn.extend({		
		toUpper: function (options){
			//转换大写
			var _this = $(this);
			
			_this.unbind("keyup").bind("keyup",function (){
				var v=_this.val();
				_this.val(v.toUpperCase());				
			});
		},
		isNotNull: function (options){
			//元素值不能为空
			var _this = $(this);
			_this.unbind("blur").blur(function (){
				var s= $(this);
				if(jQuery.trim(s.val())==""){					
					s.parent().next().html("不能为空");
					return false;
				}else{
					s.parent().next().empty();
					return true;
				}
			});
		},
		showmsg:function (txt){			
			
		}
	});
})(jQuery);

//日期 不超过 n 天
function diffday(tp_b_date,tp_e_date,interval){
	var year1,year2,month1,month2,day1,day2;
	year1=tp_b_date.substr(0,4);
	year2=tp_e_date.substr(0,4);
	month1=tp_b_date.substr(5,2);
	month2=tp_e_date.substr(5,2);
	day1=tp_b_date.substr(8,2);
	day2=tp_e_date.substr(8,2);
	var d1=new Date(year1+"/"+month1+"/"+day1);
	var d2=new Date(year2+"/"+month2+"/"+day2);
	var difference_ms=Math.abs(Math.ceil((d2-d1)/86400000));
	if(difference_ms>=interval){
		return false;
	}
	else{
		return true;
	}
}
/*
 * $author lls
 * $description 判断是否是 format:yyyy-mm-dd
 * $param name 页面元素id或name或jquery对象
 * return 日期类型 true; 反之 false
 */
function isDate(name){
	var x_l;
	if(typeof(name)=='object'){
		x_l=name;
	}else{
		x_l=$("#"+name);
	}	
	if(x_l.length<=0){
		x_l=$("[name='"+name+"']");
	}
	var d = x_l.val();
	if(d.length==0){
		x_l.showmsg("format:yyyy-mm-dd");
		return false;		
	}
	try {
         if(d.length!=10){
         	 x_l.showmsg("format:yyyy-mm-dd");
    	     return false;
    	 }else{
             for(i=0;i<d.length;i++) {
        	     c = d.charAt(i);
        	     if(!((c>='0' && c<='9') || c=='-')){
        		     x_l.showmsg("format:yyyy-mm-dd");
        		     return false;
        		 }
        	 }
		     var arra = d.split("-");
       	     if (arra.length!=3) {
       	         x_l.showmsg("format:yyyy-mm-dd");
       	    	 return false;
        	 }
        	 if (arra[1]<1 || arra[1]>12) {
        	     x_l.showmsg("format:yyyy-mm-dd");
        		 return false;
        	 }
        	 if (arra[2]<1 || arra[2]>31) {
        	     x_l.showmsg("format:yyyy-mm-dd");
        		 return false;
        	 }
	         try {
	             var dateo = new Date(arra[0],parseInt(arra[1],10)-1,arra[2]);
	        	 if ((dateo.getFullYear()!=parseInt(arra[0],10)) ||
	        		 (dateo.getMonth()+1!=parseInt(arra[1],10)) ||
	        		 (dateo.getDate()!=parseInt(arra[2],10)) ) {
	        		 x_l.showmsg("format:yyyy-mm-dd");return false;
	        	 }
	         }catch(e) {
	        	x_l.showmsg("format:yyyy-mm-dd");
	        	return false;
	        }
         }
	}catch(e) {
		x_l.showmsg("format:yyyy-mm-dd");
	    return false;
	}
	return true;	
}
function upper(obj){
     obj.value = obj.value.toUpperCase();
     return true;        
}

String.prototype.replaceAll = function(c, d) {return this.replace(new RegExp(c, "gm"), d)};
String.prototype.trim=function(){return this.replace(/^(\s|\u00A0)+|(\s|\u00A0)+$/g, "");}